var app = getApp()
Page({
    data: {
        isShowInputLabelArr: [false, false],
        goodsInfo: null,
        toastMsg: null,
    },

    onLoad: function (options) {
        console.log(options)
        if (options.goods != "undefined"){
            var obj = JSON.parse(options.goods);
            this.setData({
                goodsInfo: obj,
                isShowInputLabelArr: [true, true]
            })
        }
        console.log(this.data.goodsInfo)
        console.log('this.data.goodsInfo')
    },

    submitGoodsInfo: function (e) {
        if (e.detail.value.nums == ''){
            e.detail.value.nums == 0
        }
        var param = e.detail.value
        param.uid = app.globalData.shopInfo.userid
        var cate = this.data.goodsInfo
        if (cate){
            param.cate_id = cate.cateId
            param.sql = 'update'
        }else{
            param.sql = 'insert'
        }
        var that = this
        app.getJsonData('api/admin/pro_cate_save.php', param, function (res) {
            console.log(res)
            console.log('resData')
            that.reportResult(res)
        })
    },

    reportResult: function (res) {
        if (res.code == 0) {
            app.noticeUpdateGoodsCate(res.data)
            wx.navigateBack();
        } else {
            this.setData({
                toastMsg: res.message
            })
        }
    },

    addFail: function () {
        this.setData({
            toastMsg: null
        })
    },

    showInputLabel: function (e) {
        if (e.detail.value.length > 1) return;
        var index = Number(e.currentTarget.id);
        var isShowArray = this.data.isShowInputLabelArr;
        isShowArray[index] = true;

        this.setData({
            isShowInputLabelArr: isShowArray
        })
        console.log(isShowArray);
        console.log(this.data.isShowInputLabelArr);
        console.log(e.currentTarget.id);
    },


    onShareAppMessage: function () {

    }
})